import {connect} from 'react-redux'
import {useEffect,useState} from 'react'
import {addUserData} from '@/redux/actions/user.js'
import {addBlogData} from '@/redux/actions/blog'
// import axios from 'axios'
import axios from '@/assets/js/intercepotr'
import Background from '@/components/Member/backGround'
import InnerContainer from '@/components/Member/InnerContainer'
import './index.less'
import store from '@/redux/store.js'
import api from '@/service/index'
const Member = function(props){
  const [userData,setUserData] = useState('')
  const [userBlog,setUserBlog] = useState([])
  useEffect(()=>{
    const loginUser = store.getState().loginUser.loginUser
    let obj = {}
    obj.phone = loginUser
    // const user = store.getState().loginUser.loginUser
    getUser(obj)
    // getBlog()
  },[])// eslint-disable-line

  const getUser = async (params)=>{
    let res = await api.user.member(params)
    if(res.code === 200){
      props.addUser(res.result)
      setUserData(res.result)
      let obj = {}
      obj.userid = res.result.user.userid
      // console.log('obj',obj,res.result)
      getBlog(obj)
      // console.log('user',res.result)
    }
  }

  const getBlog = async (params)=>{
    let res = await api.blog.getBlog(params)
    if(res.code === 200){
      setUserBlog(res.result.blog)
      // props.addBlog(res.result.blog)
    }
  }

  return (
    <div className="member-container">
      <Background userData={userData.user}/>
      <InnerContainer userData={userData.user} userBlog={userBlog}/>
    </div>
  )
}

export default connect(state=>({
  userData:state.user,
  blog:state.blog
})
,{
  addUser:addUserData,
  addBlog:addBlogData
})(Member)